<template>
	<view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isWeixin: false,
				userinfo: '',
				logontrue: false,
				getBannerListByPositonlist: "",
				WxOfficialInfo: "",
				phone: "",
				codetrue: true,
				time: 60,
				code: "",
				wxcode: "",
				phonetrue: false,
				timer: null,
				wxinfo: ""
			};
		},
		onShow() {
			
		},
		onReady() {},
		onLoad(options) {
			if (uni.getStorageSync('wechat_login_tag') && this.getUrlCode('code')) {
				this.checkWeChatCode();
			}else{
				this.getWeChatCode()
			}
		},
		onHide() {
		},
		methods: {
			getWeChatCode() {
				let target = navigator.userAgent.toLowerCase();
				let isWeixin = /micromessenger/.test(target)
				if (isWeixin) {
					uni.setStorageSync('wechat_login_tag', 'true');
					const appID = "wx15cf76416ee69bb7"; //公众号appID
					// const callBack = global.baseshare + '/h5/#/'; //回调地址 就是你的完整地址登录页
					const callBack = "http://api.muxiangcl.com/share/index.html#/pages/tabBar/loginnew/loginnew"; //回调地址 就是你的完整地址登录页
					console.log(callBack, callBack, 153);
					//通过微信官方接口获取code之后，会重新刷新设置的回调地址【redirect_uri】
					// return
					window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
						appID + '&redirect_uri=' + encodeURIComponent(callBack) +
						'&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'
				} else {
					this.$message.info("请在微信浏览器打开")
				}
			},

			// 重定向回来本页面检查有没有code
			checkWeChatCode() {
				let _this = this;
				this.wxcode = this.getUrlCode('code');
				if (this.getUrlCode('code')) {
					this.$api.get(global.apiUrls.post663c92a30a8ad, {
						code:this.wxcode,
					}).then(res=>{
						if(res.data.code==1){
							_this.$store.commit('saveToken', res.data.data.user_token);
							uni.removeStorageSync("wechat_login_tag");
							uni.switchTab({
								url:"/pages/ddgl/order/order"
							})
						}
					})
				}
			},
			// 正则匹配请求地址中的参数函数
			getUrlCode(name) {
				return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||
				[, ''
				])[1].replace(/\+/g, '%20')) || null
			},
		}
	};
</script>

<style scoped>
	page{
		width: 100%;
		height: 100%;
		background-color: #fff;
	}
</style>